<template>
  <div>
    <el-dialog
      title="创建商户"
      :visible.sync="dialogVisible"
      width="30%"
      :center="true"
      :before-close="handleClose"
      @close="onClose"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="商户名称">
          <el-input v-model.trim="form.name"></el-input>
        </el-form-item>
        <el-form-item label="商户编码">
          <el-input v-model.trim="form.code"></el-input>
        </el-form-item>
        <el-form-item label="商户地址">
          <el-input v-model.trim="form.address"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSave">立即创建</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
    createCorp,         // 创建商户
} from '@/api/corpConfig'
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        name: '',
        code: '',
        address: ''
      }
    };
  },
  created() {
    this.dialogVisible = true;
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    // 保存
    onSave() {
      let arr = []
      arr.push(this.form)
      createCorp(arr).then(res => {
        console.log(res)
      }, err => {
        console.log('error')
      })
    },
    // 弹窗关闭前执行
    onClose() {
      this.$emit("addCorpDialog", false);
    }
  }
};
</script>

